package com.bj58.groupbuy.action.util;

import java.util.ArrayList;
import java.util.List;

import com.bj58.groupbuy.action.db.CommonDao;
import com.bj58.groupbuy.action.db.DBConfig;

/**权限批处理工具
 * @author huangliang
 *
 */
public class PermissionUtil {
	
	private CommonDao comDao = new CommonDao();
	
	
	@SuppressWarnings("static-access")
	public void addNewOpersToUsers(List<String> menuIds ,List<String> userIds){
		String inserSql = "insert into user_priviledge values ('%s','%s')";
		for(String menuId : menuIds){
			
			for(String userId : userIds){
				try {
					comDao.executeSql(inserSql.format(inserSql, userId ,menuId), DBConfig.db_68_bi_sys.getIntType());
				} catch (Exception e) {
					e.printStackTrace();
					continue;
				}
			}
			
		}
		
	}
	
	public static void main(String[] args) {
		try {
			List<String> menuIds = new ArrayList<String>();
			menuIds.add("372");
			
			String sql = "SELECT DISTINCT userid  FROM `user_priviledge` where menuid = 278 ";
			CommonDao comDao = new CommonDao();
			List<String> userIds = comDao.searchReturnStrings(sql, DBConfig.db_68_bi_sys.getIntType());
			PermissionUtil pu = new PermissionUtil();
			pu.addNewOpersToUsers(menuIds, userIds);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
